import {ipcMain} from 'electron'
import si from 'systeminformation'

ipcMain.handle('get-hardware-info', async () => {
  try {
    const cpuInfo = await si.cpu()
    const systemInfo = await si.osInfo()
    const memoryInfo = await si.mem()
    const diskInfo = await si.diskLayout()
    const gpuInfo = await si.graphics()
    const baseboard = await si.baseboard()

    return {
      cpuInfo: cpuInfo,
      systemInfo: systemInfo,
      memoryInfo: memoryInfo,
      diskInfo: diskInfo,
      gpuInfo: gpuInfo,
      baseboard: baseboard
    }
  } catch (error) {
    console.error('获取硬件信息失败:', error)
    throw error
  }
})

ipcMain.handle('get-hardware-info-type', async (event, hardwareType) => {
  try {
    // 根据传入的硬件类型，返回对应的信息
    switch (hardwareType) {
      case 'cpuInfo':
        return await si.cpu()
      case 'systemInfo':
        return await si.osInfo()
      case 'memoryInfo':
        return await si.mem()
      case 'diskInfo':
        return await si.diskLayout()
      case 'gpuInfo':
        return await si.graphics()
      case 'baseboard':
        return await si.baseboard()
      default:
        return {}
    }
  } catch (error) {
    console.error('获取硬件信息失败:', error)
    throw error
  }
})

